<template>
  <div>
    <!--登陆头部-->
    <van-nav-bar title="面经注册" />
    <!--表单内容-->
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="username"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="password"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
    <span class="login" @click="gologin">已有账号,去登陆</span>
  </div>
</template>
<script>
// import request from '../utils/index'
import { register } from '../api/userInfo.js'//导入api注册接口
export default {
  data () {
    return {
      username: '',
      password: '',
    };
  },
  methods: {
    async onSubmit (values) {
      console.log('submit', values);
      const res = await register(values)
      console.log(res);
      if (res.message === '请求成功') {
        this.$toast('注册成功')//注册成功提示
        // this.$router.push('/')
      } else {
        this.$toast('注册失败')
      }
      console.log(res);
    },
    gologin () {
      this.$router.push('login')
    }
  },
};
</script>
<style lang='less'  scoped>
.login {
  font-size: 14px;
  float: right;
  color: #666;
  margin: 10px;
  cursor: pointer;
}
</style>
